/*
 Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
 Original sources are available at www.latestbit.com

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

 IManagedConnection.hpp. Created on: 19.08.2009 12:05:40
 */

#ifndef IMANAGEDCONNECTION_HPP_
#define IMANAGEDCONNECTION_HPP_

#include "smartobjects/SmartObjectsDefs.hpp"
#include "ICoordinatorContext.hpp"
#include "IEndpointLocation.hpp"

namespace smartobjects {

class IManagedConnection : public virtual RefObject {
public:
	SO_DLLPRFX virtual ~IManagedConnection();
	virtual bool isOpen() = 0;
	virtual void stop() = 0;
	virtual IEndpointLocation* getEndpointLocation() = 0;

	virtual class ConnectionHandler* getConnectionHandlerToSend() = 0;
	virtual void send(class ConnectionHandler* poHandler, const ByteBuffer* poBuffer)= 0;

	virtual void addConnectionListener(class IManagedConnectionListener*) = 0;
	virtual void delConnectionListener(class IManagedConnectionListener*) = 0;

	virtual void addStreamListener(class IManagedStreamListener*) = 0;
	virtual void delStreamListener(class IManagedStreamListener*) = 0;

	virtual void assignConnectionHandler(class ConnectionHandler*) = 0;
	virtual void unassignConnectionHandler(class ConnectionHandler*) = 0;

	virtual void fireOnConnected() = 0;
	virtual void fireOnConnected(class ConnectionHandler* poHandler) = 0;

	virtual void fireOnConnectionFailure( const std::string& sErrorMessage) = 0;
	virtual void fireOnConnectionFailure(class ConnectionHandler* poHandler, const std::string& sErrorMessage) = 0;

	virtual void fireOnDisconnected() = 0;
	virtual void fireOnDisconnected(class ConnectionHandler* poHandler) = 0;

	virtual void fireOnReceived(class ConnectionHandler* poHandler, ByteBuffer* buffer) = 0;

	virtual void fireOnReceiveError(class ConnectionHandler* poHandler, const std::string& sErrorMessage) = 0;
	virtual void fireOnWriteError(class ConnectionHandler* poHandler, const std::string& sErrorMessage) = 0;

	virtual ICoordinatorContext* getCoordinatorContext() = 0;
	virtual void setCoordinatorContext(ICoordinatorContext*) = 0;
};

}

#endif /* IMANAGEDCONNECTION_HPP_ */
